package com.yx.admin;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import com.yx.frame.builder.ServiceBuilder;
import com.yx.filesystem.monitor.StorageMonitor;


public class StartDialog extends Composite {
	private final FormToolkit formToolkit = new FormToolkit(Display.getDefault());
	
	/**
	 * Create the composite.
	 * @param parent
	 * @param style
	 */
	public StartDialog(Composite parent, int style) {
		super(parent, style);
		Composite composite = new Composite(this, SWT.BORDER | SWT.NO_BACKGROUND);
		composite.setBounds(10, 10, 156, 164);
		formToolkit.adapt(composite);
		formToolkit.paintBordersFor(composite);
		
		Button btnNewButton_1 = formToolkit.createButton(composite, "StorageMonitor", SWT.NONE);
		btnNewButton_1.setBounds(10, 49, 135, 27);
		
		Button btnNewButton = formToolkit.createButton(composite, "SmartBuilder", SWT.NONE);
		btnNewButton.setBounds(10, 11, 135, 27);
		
		Button btnNewButton_2 = new Button(composite, SWT.NONE);
		btnNewButton_2.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				StorageServer.main(null);
			}
		});
		btnNewButton_2.setBounds(10, 87, 135, 27);
		formToolkit.adapt(btnNewButton_2, true, true);
		btnNewButton_2.setText("StorageServerConfig");
		
		Button btnWebserverconfig = new Button(composite, SWT.NONE);
		btnWebserverconfig.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				try {
					WebServer.main(null);
				} catch (Exception ex) {
					ex.printStackTrace();
				}
			}
		});
		btnWebserverconfig.setText("WebServerConfig");
		btnWebserverconfig.setBounds(10, 125, 135, 27);
		formToolkit.adapt(btnWebserverconfig, true, true);
		btnNewButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				//String command=" java -Dfile.encoding=\"UTF-8\" -cp ServiceBuilder.jar com.yx.frame.server.Builder ";
				try {
					ServiceBuilder window = new ServiceBuilder();
					window.open();
				} catch (Exception ex) {
					ex.printStackTrace();
				}
			}
		});
		btnNewButton_1.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				try {			
					StorageMonitor window = new StorageMonitor();
					window.open();
				} catch (Exception ex) {
					ex.printStackTrace();
				}
			}
		});

	}

	@Override
	protected void checkSubclass() {
		// Disable the check that prevents subclassing of SWT components
	}
	public static void exec(String command) {
        String s = null;
        try {
            Process process = Runtime.getRuntime().exec(command);
            BufferedReader bufferedReader = new BufferedReader(
                    new InputStreamReader(process.getInputStream()));
            while ((s = bufferedReader.readLine()) != null)
                System.out.println(s);
            //process.waitFor();
        }catch (Exception e) {           
            e.printStackTrace();
        }
       
    }
}
